
<html>
<head>
    <title>分页显示成语</title>
    <style>
        h1{ color: red;}
        .list{
            display: flex;
            width: 400px;
            justify-content: space-around;
            border: 5px double red;
            padding: 10px;
        }
        .list>div{
            border:1px solid gray;
            padding: 10px;
        }
        </style>
</head>
<body>
<?php
$db=new PDO('mysql:host=localhost;dbname=db','root','12qwas');
$total=$db->query("select count(*) from chengyu")->fetchColumn();//成语的总数
$lanNums=5;//栏目总数
$lanSize=10;//一个栏目包含成语个数
$pageSize=$lanNums*$lanSize;//一个页面显示的成语总数
$pageTotal=ceil($total/$pageSize);
$page=(int)$_GET ['pag'];
if($page<1)$page=1;
else if ($page>$pageTotal)$page=$pageTotal;
$n=6;
$begin=$page-$n;
$over=$page+$n;
if ($begin<1){
    $begin=1;
    $over=2*$n=1;
    if ($over>$pageTotal)$over=$pageTotal;
}else if($over>$pageTotal){
    $begin=$pageTotal-2*$n;
    $over=$pageTotal;
}
if ($begin<1)$begin=1;
if ($over>$pageTotal)$over=$pageTotal;

?>
<h1>中国成语大全</h1>
<div class="nav"><?php
    for($i=$begin;$i<=$over;$i++){

    }
    ?>
    <a href="?page=1">1</a>
    <a href="?page=2">2</a>
</div>
<div class="list">
    <div>
        <div>一穷二白</div>
        <div>一穷二白</div>
        <div>一穷二白</div>
        <div>一穷二白</div>
    </div>
</div>
</body>
</html>